// pages/app/user/valiMobile/valiMobile.js
const app = getApp();
var host = app.globalData.host;
var utils = app.globalData.utils;
var self = null;

Page({
  data: {
    themeColor: '',
    themeColor2: '',
    themeColor3: '',
    defaultColor: '',
    borderColor: '',
    mobile: '',
    code: ''
  },
  onLoad: function (options) {
    self = this;
    self.getStyle();
  },
  getStyle() {
    self.setData({
      themeColor: app.globalData.themeColor,
      themeColor2: app.globalData.themeColor2,
      themeColor3: app.globalData.themeColor3,
      defaultColor: app.globalData.defaultColor,
      borderColor: app.globalData.borderColor
    })
  },
  onMobileChange(e) {
    self.setData({
      mobile: e.detail.value
    })
  },
  onCodeChange(e) {
    self.setData({
      code: e.detail.value
    })
  },
  sendCode(e) {
    if (!self.data.mobile) {
      wx.showToast({
        title: '请输入手机号',
        icon: 'none'
      })
      return;
    }
    var url = host + '/lx/mini/user/sendCode';
    var params = {
      mobile: self.data.mobile
    };
    var success = function (res) {
      wx.showToast({
        title: '验证码发送成功',
        icon: 'none'
      })
    }
    var fail = function () { };
    var complete = function () { };
    utils.request(url, params, success, fail, complete);
  },
  next(e) {
    if (!self.data.mobile) {
      wx.showToast({
        title: '请输入手机号',
        icon: 'none'
      })
      return;
    }
    if (!self.data.code) {
      wx.showToast({
        title: '请输入验证码',
        icon: 'none'
      })
      return;
    }
    var url = host + '/lx/mini/user/validateMobile';
    var params = {
      mobile: self.data.mobile,
      code: self.data.code
    };
    var success = function (res) {
      wx.navigateTo({
        url: '/pages/app/user/signUp/signUp?uid=' + res.info.id + '&account=' + res.info.account
      })
    }
    var fail = function () { };
    var complete = function () { };
    utils.request(url, params, success, fail, complete);
  }
})